package com.stock.stockana.model;

import android.content.AsyncTaskLoader;
import android.content.Context;
import android.database.Cursor;

import com.stock.stockana.StockCenter;

/**
 * Created by ljgsonx on 2016/1/22.
 */
public class StockCursorLoader extends AsyncTaskLoader<Cursor> {

    public final static int ID = 0;

    private StockService mStockService;

    public static String mSearchKey;

    public StockCursorLoader(Context context) {
        super(context);
        mStockService = StockCenter.getStockService();
    }

    @Override
    public Cursor loadInBackground() {
        return mStockService.getStockByLikingMethod(mSearchKey);
    }

    @Override
    protected void onStartLoading() {
        super.onStartLoading();
        if(mSearchKey != null) forceLoad();
    }

    @Override
    public void onCanceled(Cursor data) {
        super.onCanceled(data);
        if(null != data){
            data.close();
        }
    }
}
